#include "ToolButton.h"
#include "ToolBase.h"
#include "ToolBar.h"

ToolButton::ToolButton(QWidget *parent, ToolBase * tool)
    : QToolButton(parent), m_tool(tool)
{
    setCheckable(true);
    setAutoRaise(true);
    QPixmap pix(tool->iconPath());
    setIconSize(pix.size());

    QIcon icon(pix);

    QFileInfo fileInfo(tool->iconPath());
    QString iconDown = fileInfo.dir().path() + '/' + fileInfo.baseName() + "_down." + fileInfo.completeSuffix();
    if (QFile::exists(iconDown)) {
        icon.addFile(iconDown, pix.size(), QIcon::Normal, QIcon::On);
    }
    QString iconHover = fileInfo.dir().path() + '/' + fileInfo.baseName() + "_hover." + fileInfo.completeSuffix();
    if (QFile::exists(iconHover)) {
        icon.addFile(iconHover, pix.size(), QIcon::Active);
    }
    setIcon(icon);
    setToolTip(tool->toolTip());
}
